package com.atguigu.stack;

import java.util.ArrayDeque;
import java.util.Deque;

public class MyQueue {
    private Deque<Integer>master;
    private Deque<Integer>slave;
    public MyQueue(){
        master=new ArrayDeque<>();
        slave=new ArrayDeque<>();
    }
    public void push(int x){
        master.addLast(x);
    }
    public int pop(){
        if(slave.isEmpty()){
            while(!master.isEmpty()){
                slave.addLast(master.removeLast());
            }
        }
        return slave.removeLast();
    }
    public int peek(){
        if(slave.isEmpty()){
            while(!master.isEmpty()){
                slave.addLast(master.removeLast());
            }
        }
        return slave.peekLast();
    }
    public boolean empty(){
        return master.isEmpty()&&slave.isEmpty();
    }
}
